//
//  BottomTopLineView.m
//  EPTool
//
//  Created by guoshiqing on 2018/4/12.
//  Copyright © 2018年 云数动能科技. All rights reserved.
//

#import "BottomTopLineView.h"
#import "Masonry.h"
#import "Macro.h"
#import "EPColor.h"

@interface BottomTopLineView ()

@property (nonatomic, strong) UIView *bottomLine;
@property (nonatomic, strong) UIView *topLine;

@end

@implementation BottomTopLineView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        [self setBaseLine];
    }
    return self;
}

//registerNib会调用awakeFromNib
- (void)awakeFromNib
{
    [super awakeFromNib];
    [self setBaseLine];
}

#pragma mark - bottomLine

- (void)setBaseLine
{
    if (!_bottomLine)
    {
        _bottomLine = [[UIView alloc] init];
        _bottomLineColorStyle = BottomTopLineColorStyleLight;
        _bottomLine.layer.backgroundColor = [EPColor epColor_UnderLine].CGColor;
        [self addSubview:_bottomLine];
        WEAKSELF;
        [_bottomLine mas_makeConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo(0.5);
            make.left.mas_equalTo(weakSelf.mas_left);
            make.bottom.mas_equalTo(weakSelf);
            make.right.mas_equalTo(weakSelf);
        }];
    }
}



- (void)setBottomLineLeftEdge:(CGFloat)bottomLineLeftEdge
{
    WEAKSELF;
    [_bottomLine mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(weakSelf.mas_left).offset((bottomLineLeftEdge));
    }];
}

- (void)setBottomLineRightEdge:(CGFloat)bottomLineRightEdge
{
    WEAKSELF;
    [_bottomLine mas_updateConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(weakSelf.mas_right).offset((38-bottomLineRightEdge));
    }];
}

- (void)setBottomLineHidden:(BOOL)bottomLineHidden
{
    _bottomLine.hidden = bottomLineHidden;
}

- (void)setBottomLineColorStyle:(BottomTopLineColorStyle )bottomLineColorStyle
{
    _bottomLineColorStyle = bottomLineColorStyle;
    switch (bottomLineColorStyle) {
        case BottomTopLineColorStyleLight:
        case BottomTopLineColorStyle_line1:
        {
            _bottomLine.layer.backgroundColor = [EPColor epColor_UnderLine].CGColor;
        }
            break;
        case BottomTopLineColorStyleDark:
        case BottomTopLineColorStyle_line2:
        {
            _bottomLine.layer.backgroundColor = RGB_HEX(0xf0f0f0).CGColor;
        }
            break;
        case BottomTopLineColorStyleWhite:
        {
            _bottomLine.layer.backgroundColor = [UIColor whiteColor].CGColor;
        }
            break;
        default:
            break;
    }
}

#pragma mark - topLine

- (UIView *)topLine
{
    if (!_topLine)
    {
        _topLine = [[UIView alloc] init];
        _topLineColorStyle = BottomTopLineColorStyleLight;
        _topLine.layer.backgroundColor = [EPColor epColor_UnderLine].CGColor;
        [self addSubview:_topLine];
        WEAKSELF;
        [_topLine mas_makeConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo(0.5);
            make.left.mas_equalTo(weakSelf.mas_left);
            make.top.mas_equalTo(weakSelf);
            make.right.mas_equalTo(weakSelf);
        }];
    }
    return _topLine;
}


- (void)setTopLineLeftEdge:(CGFloat)setTopLineLeftEdge
{
    WEAKSELF;
    [_topLine mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(weakSelf.mas_left).offset((setTopLineLeftEdge));
    }];
}

- (void)setTopLineRightEdge:(CGFloat)topLineRightEdge
{
    WEAKSELF;
    [_topLine mas_updateConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(weakSelf.mas_right).offset((38-topLineRightEdge));
    }];
}

- (void)setTopLineHidden:(BOOL)topLineHidden
{
    if (topLineHidden) {
        _topLine.hidden = YES;
    }
    else{
        self.topLine.hidden = NO;
    }
}

- (void)setTopLineColorStyle:(BottomTopLineColorStyle)topLineColorStyle
{
    _topLineColorStyle = topLineColorStyle;
    switch (topLineColorStyle) {
        case BottomTopLineColorStyleLight:
        case BottomTopLineColorStyle_line1:
        {
            _topLine.layer.backgroundColor = [EPColor epColor_UnderLine].CGColor;
        }
            break;
        case BottomTopLineColorStyleDark:
        case BottomTopLineColorStyle_line2:
        {
            _topLine.layer.backgroundColor = RGB_HEX(0xf0f0f0).CGColor;
        }
            break;
        case BottomTopLineColorStyleWhite:
        {
            _topLine.layer.backgroundColor = [UIColor whiteColor].CGColor;
        }
            break;
        default:
            break;
    }
}


@end
